/* 
 * File:   AveragePixelIntensity.cpp
 * Author: guilhermemg
 * 
 * Created on 21 de Fevereiro de 2012, 22:23
 */

#include "AveragePixelIntensity.h"

AveragePixelIntensity::AveragePixelIntensity() {
    setName("f1");
    setLargeName("f1 - averagePixelIntensity");
}

AveragePixelIntensity::AveragePixelIntensity(const AveragePixelIntensity& orig) {
}

AveragePixelIntensity::~AveragePixelIntensity() {
}

void AveragePixelIntensity::calculates() {
    double sum = 0;
    
    for(int i = 0; i < this->getImage()->height; i++) {
        uchar* ptr = (uchar*)(this->getImage()->imageData + i*this->getImage()->widthStep);
        for(int j = 0; j < this->getImage()->width; j++) {
            sum += ptr[3*j + 2];
        }
    }
    
    sum = (sum/255)*100;
    
    // faz a media aritmetica para a imagem toda
    setValue(sum/(double)(this->getImage()->height * this->getImage()->width));
}
